﻿using Architecture.API.Application.TraceabilityCommand.EnterpriseCommand;
using MediatR;
using Traceability.Domain;
using Traceability.Domain.Service.EnterpriseServices;

namespace Architecture.API.Application.TraceabilityCommandHandler.EnterpriseCommandHandler
{
    /// <summary>
    /// 企业信息创建命令处理器
    /// </summary>
    public class AddBreedEnterpriseCommandHandler : IRequestHandler<AddBreedEnterpriseCommand, int>
    {
        /// <summary>
        /// 企业服务
        /// </summary>
        protected readonly IEnterpriseService enterpriseService;

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="enterpriseService">企业服务</param>
        public AddBreedEnterpriseCommandHandler(IEnterpriseService enterpriseService)
        {
            this.enterpriseService = enterpriseService;
        }

        /// <summary>
        /// 添加养殖企业信息
        /// </summary>
        /// <param name="request">请求</param>
        /// <param name="cancellationToken">取消标记</param>
        /// <returns>返回受影响的行数</returns>
        public async Task<int> Handle(AddBreedEnterpriseCommand request, CancellationToken cancellationToken)
        {
            return await enterpriseService.AddEnterpriseBreed(request.shoppingId, new Enterprise() { livestockFarm=request.livestockFarm,PersonInCharge=request.PersonInCharge,InventoryQuantity=request.InventoryQuantity,ShoppingId=request.shoppingId, CreatedBy=request.CreatedBy,CreatedDate=DateTime.Now });
        }
    }
}
